if getOne([#cast, #animatorCast, #keyframeCast], type) > 0 then
puppetSound(Channel, cast the number of cast name)
else
if getOne([#ambientLoop, #File, #FileLooped, #animatorFile, #keyframeFile, #keyframeFileLooped], type) > 0 then
sound playFile Channel, gSoundPath & name
else
displayChaosError(#info, "Sound type undefined:" && string(type))
exit
end if
end if
else
displayChaosError(#warning, "Ran out of sound channels attempting to play:" && name)
exit
end if
if (bWaitFor = #NOW) and (Channel <> 0) then
updateStage()
else
if bWaitFor and (Channel <> 0) then
cursor([the number of cast "NullCursor", the number of cast "NullCursor.mask"])
updateStage()
repeat while soundBusy(Channel)
cursorandupdate()
end repeat
end if
end if
set gLastSoundChannel to Channel
return Channel
end
on waitForSoundDone Channel
repeat while soundBusy(Channel)
cursorandupdate()
end repeat
end
on setSoundState action
if action = #pause then
puppetSound(0)
repeat with Channel = 1 to 8
set theSoundData to getaProp(gSoundChannels, Channel)
if not voidp(theSoundData) then
set the status of getaProp(gSoundChannels, Channel) to #paused
sound stop Channel
end if
end repeat
exit
end if
if action = #play then
repeat with Channel = 1 to 8
set theSoundData to getaProp(gSoundChannels, Channel)
if not voidp(theSoundData) then
if the type of theSoundData = #keyframeCast then
deleteProp(gSoundChannels, Channel)
next repeat
end if
playSound(the name of theSoundData, the type of theSoundData)
end if
end repeat
exit
end if
displayChaosError(#info, "Sound state undefined:" && string(action))
end
on displayChaosError type, message
if type = #info then
set errorMessage to "Chaos Error - Information" & RETURN & RETURN & message
else
if type = #warning then
set errorMessage to "Chaos Error - Warning" & RETURN & RETURN & message
else
if type = #severe then
set errorMessage to "Chaos Error - Severe" & RETURN & RETURN & message & RETURN & RETURN & "You should probably quit now."
end if
end if
end if
alert(errorMessage)
end
on playSoundTerry name, type, bWaitFor
if type = #ambientCast then
set Channel to 1
puppetSound(name)
set theSoundData to [:]
addProp(theSoundData, #name, name)
addProp(theSoundData, #type, type)
addProp(theSoundData, #status, #playing)
setaProp(gSoundChannels, Channel, theSoundData)
if bWaitFor then
repeat while soundBusy(Channel)
cursorandupdate()
end repeat
end if
set gLastSoundChannel to Channel
return Channel
else
if type = #ambientLoop then
set Channel to 2
set theSoundData to getaProp(gSoundChannels, Channel)
if voidp(theSoundData) then
set theSoundData to [:]
addProp(theSoundData, #name, name)
addProp(theSoundData, #type, type)
addProp(theSoundData, #status, #playing)
setaProp(gSoundChannels, Channel, theSoundData)
else
if the name of theSoundData = name then
if the status of theSoundData = #playing then
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
else
set the status of getaProp(gSoundChannels, Channel) to #playing
end if
else
set the name of getaProp(gSoundChannels, Channel) to name
set the type of getaProp(gSoundChannels, Channel) to type
set the status of getaProp(gSoundChannels, Channel) to #playing
end if
end if
sound playFile Channel, gSoundPath & name
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
else
if (type = #keyframeFile) or (type = #keyframeFileLooped) or (type = #keyframeCast) then
set Channel to 3
set theSoundData to getaProp(gSoundChannels, Channel)
if voidp(theSoundData) then
set theSoundData to [:]
addProp(theSoundData, #name, name)
addProp(theSoundData, #type, type)
addProp(theSoundData, #status, #playing)
addProp(gSoundChannels, Channel, theSoundData)
else
if the name of theSoundData = name then
if the status of theSoundData = #playing then
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
else
set the status of getaProp(gSoundChannels, Channel) to #playing
end if
else
set the name of getaProp(gSoundChannels, Channel) to name
set the type of getaProp(gSoundChannels, Channel) to type
set the status of getaProp(gSoundChannels, Channel) to #playing
end if
end if
if type = #keyframeCast then
puppetSound(Channel, cast the number of cast name)
else
sound playFile Channel, gSoundPath & name
end if
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
else
if getOne([#File, #FileLooped, #cast, #animatorCast, #ambientLoop, #animatorFileLooped], type) > 0 then
set freeChannel to 0
repeat with Channel = 4 to 8
set theSoundData to getaProp(gSoundChannels, Channel)
if not voidp(theSoundData) then
if (the name of theSoundData = name) and (the type of theSoundData = type) then
if the status of theSoundData = #playing then
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
else
set the status of getaProp(gSoundChannels, Channel) to #playing
if bWaitFor then
waitForSoundDone(Channel)
end if
set gLastSoundChannel to Channel
return Channel
end if
else
if (the status of theSoundData = #playing) and not soundBusy(Channel) and (the type of theSoundData <> #FileLooped) and (the type of theSoundData <> #animatorFileLooped) then
set freeChannel to Channel
exit repeat
end if
end if
next repeat
end if
set freeChannel to Channel
exit repeat
end repeat
if freeChannel > 0 then
set theSoundData to getaProp(gSoundChannels, freeChannel)